﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tetris
{
    class GameField
    {
        public List<Shape> _ShapesInField;
        private int Height;
        private int Width;
        public int Heights
        {
            get
            {
                return Height;
            }
        }
        public int Widths
        {
            get
            {
                return Width;
            }
        }
        public GameField(int first, int second)
        {
            this.Height = first;
            this.Width = second;
            _ShapesInField = new List<Shape>();
        }
        public void AddShape(Shape s)
        {
            _ShapesInField.Add(s);
        }
        public void RemoveRow(int Row)
        {
            for (int j = 0; j <= Width; j++)
            {
                foreach (Shape item in _ShapesInField)
                {
                    item.RemovePoint(j, Row);
                }
            }
            foreach (Shape item in _ShapesInField)
            {
                foreach (Point ofitem in item.Coordinates)
                {
                    if (ofitem.y > Row)
                    {
                        ofitem.PlusY();
                    }
                }
            }
        }
        public int IsPositionFree(int x, int y)
        {
            foreach (Shape item in _ShapesInField)
            {
                foreach (Point ofitem in item.Coordinates)
                {
                    if (x == ofitem.x && y == ofitem.y)
                    {
                        return 1;
                    }
                }
            }
            if (x < 0 || x >= Widths)
            {
                return 1;
            }
            else if (y >= Height)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
    }
}
